package com.yl.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yl.dao.IGoodsDao;
import com.yl.dto.GoodsDTO;
import com.yl.model.Goods;
@Service
public class GoodsService implements IGoodsService {

	
	@Resource
	private IGoodsDao goodsDao;
	
	/**
	 *后台商品列表
	 */
	public Map findAll(GoodsDTO dto) {
		List<Goods> list = goodsDao.findAll(dto);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "查询成功");
		map.put("count", goodsDao.getCount(dto));
		map.put("data", list);
		return map;
	}

	/**
	 *后台推荐商品（0改1就是推荐，1改0就是取消推荐）
	 */
	public int recommend(Goods good) {
		return goodsDao.recommend(good);
	}

	/**
	 *后台上架(0改1就是上架，1改0就是下架)
	 */
	public int sale(Goods goods) {
		return goodsDao.sale(goods);
	}

	/**
	 *后台更换图片
	 */
	public int picture(int goods_id, String picture) {
		return goodsDao.picture(goods_id, picture);
	}

	/**
	 *后台新增商品
	 */
	public int add(Goods goods) {
		return goodsDao.add(goods);
	}

	/**
	 *后台根据id删除商品
	 */
	public int del(int goods_id) {
		return goodsDao.del(goods_id);
	}

	/**
	 *后台更新商品信息
	 */
	public int edit(Goods goods) {
		return goodsDao.edit(goods);
	}

	/**
	 *后台查询符合筛选条件的总记录数
	 */
	@Override
	public int getCount(GoodsDTO dto) {
		return goodsDao.getCount(dto);
	}

	/**
	 *后台查询商品详情
	 */
	@Override
	public Goods findById(int goods_id) {
		return goodsDao.findById(goods_id);
	}

	/**
	 *查询今日必抢
	 */
	@Override
	public List<Goods> findToday() {
		return goodsDao.findToday();
	}

	/**
	 *更多推荐
	 */
	@Override
	public Map findAllrecommend() {
		List<Goods> list = goodsDao.findAllrecommend();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "查询成功");
		map.put("count", list.size());
		map.put("data", list);
		return map;
	}

}
